﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Web.Domain.Abstract;
using Web.Domain.Entities;

namespace Web.Domain.Concrete
{
    public class EFTypeNavRepository : ITypeRepository
    {
        private EFDbContext context = new EFDbContext();
        //默认查询
        public IQueryable<TypeNav> TypeNavs
        {
            get
            {
                return context.TypeNavs;
            }
        }
        //添加和编辑
        public bool SaveType(TypeNav typeNav)
        {
            if (typeNav.id == 0)
            {
                context.TypeNavs.Add(typeNav);
            }
            else
            {
                TypeNav dbEntry = context.TypeNavs.Find(typeNav.id);
                if (dbEntry != null)
                {
                    dbEntry.title = typeNav.title;
                    dbEntry.a = typeNav.a;
                    dbEntry.c = typeNav.c;
                    dbEntry.p = typeNav.p;
                    dbEntry.rank = typeNav.rank;
                }
            }
            if (context.SaveChanges() != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
